<!--XOA KHUYEN MAI-->
<?php
if (isset($_GET['remove']))
{
    $khuyenmaiid = $_GET ['khuyenmaiid'];
    $result = mysql_query("DELETE FROM khuyenmai where khuyenmaiid = $khuyenmaiid; ");
    if ($result)
        print '<h2>Xóa thành công !</h2>';
}
?>

<!--FORM THEM KHUYEN MAI-->
<form action="index.php?quanlybanhang&module=khuyenmai" method="post" enctype="multipart/form-data">
<fieldset>
<legend><h1>Thêm gói khuyến mại</h1></legend>
<table width="408" border="0">
  <tr>
    <td width="300">Tên gói</td>
    <td width="318"><label>
      <input type="text" name="tenkhuyenmai" id="textfield" />
    </label></td>
  </tr>
  <tr>
    <td>Áp dụng với trên </td>
    <td><input type="text" name="dieukiensoluong"/> áo<td>
  </tr>
  <tr>
    <td>Giảm giá ban đầu</td>
    <td><input type="text" value="0" onfocus="this.value=''" name="giamgia"/> %</td>
  </tr>
  <tr>
    <td>Tặng thêm</td>
    <td><input type="text" name="aotangthem"/> áo</td>
  </tr>
  <tr>
    <td>Chú ý, quà tặng..</td>
    <td><label>
    <textarea name="chuy" id="chuy"></textarea>
    </label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input class="button" type="submit" name="submit" value="Thêm" /></td>
  </tr>
</table>
</fieldset>
</form>

<!--PHP THEM LOAI khuyenmai-->
<?php
if (isset($_POST['submit']))
{
    //print_r ($_POST);
    $tenkhuyenmai      =   $_POST['tenkhuyenmai'];
    $giamgia        =   $_POST['giamgia'];
    $chuy =   $_POST['chuy'];
    $aotangthem        =   $_POST['aotangthem'];
    $dieukiensoluong        =   $_POST['dieukiensoluong'];
    $mysql = "insert into khuyenmai (tenkhuyenmai, giamgia, chuy, aotangthem, dieukiensoluong) values ('$tenkhuyenmai', '$giamgia', '$chuy', '$aotangthem', '$dieukiensoluong')";
    $result = mysql_query($mysql);
    if ($result)
        print '<h2>Thành công !</h2>';
    
    
}
?>

<!--HIEN THI CAC GOI KHUYEN MAI-->
<fieldset>
<legend><h1>Các gói đang áp dụng :</h1></legend>
<table width="695" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center" width="100"><b>ID</b></td>
        <td align="center"  width="300"><b>Tên gói</b></td>
        <td align="center"  width="200"><b>Trên </td>
        <td align="center"  width="200"><b>Giảm giá</b></td>
        <td align="center"  width="200"><b>Tặng thêm</b></td>
        <td align="center"  width="400"><b>Chú ý</b></td>
        <td align="center"  width="200"><b>Sửa / Xóa</b></td>
    </tr>

    <?php
        $khuyenmai = mysql_query("select * from `khuyenmai`");
        while ($row = mysql_fetch_array($khuyenmai))
        {
    ?>
    <tr>
        <td align="center" ><?php print "$row[khuyenmaiid]"; ?> </td>
        <td><?php print "$row[tenkhuyenmai]"; ?> </td>
        <td align="center" ><?php print "$row[dieukiensoluong]"; ?> áo</td>
        <td align="center" ><?php print "$row[giamgia]";?>% </td>
        <td align="center" ><?php print "$row[aotangthem]";?> áo</td>
        <td><?php print "$row[chuy]"; ?> </td>
        <td align="center" >
        <a href="index.php?quanlybanhang&module=suakhuyenmai&khuyenmaiid=<?php print "$row[khuyenmaiid]"; ?>&edit">Sửa</a> /
        <a href="index.php?quanlybanhang&module=khuyenmai&khuyenmaiid=<?php print "$row[khuyenmaiid]"; ?>&remove" onclick="return confirm('Muốn xóa thật ko?')" >Xóa</a>
        </td>
    </tr>
    <?php 
        }
    ?>
</table>
</fieldset>
